﻿using System;
using System.Linq;

static class MyMath
{
    // 基本运算
    public static double Add(double a, double b) => a + b;
    public static double Subtract(double a, double b) => a - b;
    public static double Multiply(double a, double b) => a * b;
    public static double Divide(double a, double b) => b == 0 ? throw new DivideByZeroException("除数不能为零") : a / b;

    // 多参数运算使用LINQ
    public static double Sum(params double[] numbers) => numbers.Sum();
    public static double Product(params double[] numbers) => numbers.Aggregate(1.0, (acc, x) => acc * x);
    public static double Average(params double[] numbers) => numbers.Average();
    public static double Max(params double[] numbers) => numbers.Max();
    public static double Min(params double[] numbers) => numbers.Min();

    // 扩展方法形式
    public static double Square(this double x) => x * x;
    public static double Cube(this double x) => x * x * x;
}

class Program
{
    static void Main()
    {
        Console.WriteLine("简洁版MyMath测试");

        // 基本运算
        Console.WriteLine($"5 + 3 = {MyMath.Add(5, 3)}");
        Console.WriteLine($"5 - 3 = {MyMath.Subtract(5, 3)}");
        Console.WriteLine($"5 × 3 = {MyMath.Multiply(5, 3)}");
        Console.WriteLine($"15 ÷ 3 = {MyMath.Divide(15, 3)}");

        // 多参数运算
        Console.WriteLine($"1+2+3+4 = {MyMath.Sum(1, 2, 3, 4)}");
        Console.WriteLine($"2×3×4 = {MyMath.Product(2, 3, 4)}");

        // 扩展方法
        double num = 5;
        Console.WriteLine($"{num}² = {num.Square()}");
        Console.WriteLine($"{num}³ = {num.Cube()}");
    }
}